package com.htfg.cardActivate.order.controller;

import com.htfg.cardActivate.core.ResultData;
import com.htfg.cardActivate.order.entity.Order;
import com.htfg.cardActivate.order.service.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * @Auther: 王晨缘
 * @Date: 2018/10/25 0025 15:59
 * @Description:
 */
@Api(value = "订单处理")
@Controller
@RequestMapping("/order")
public class OrderController {
    @Resource
    private OrderService orderService;

    @ApiOperation(value = "创建订单接口", notes = "创建订单")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "uid", value = "用户id", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "bankName", value = "银行名称", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "用户姓名", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "mobile", value = "用户手机号", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "address", value = "用户地址", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "lon", value = "经度", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "lat", value = "纬度", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "visitTime", value = "上门时间", required = true, dataType = "String", paramType = "query"),
    })
    @RequestMapping(value = "/createOrder", method = RequestMethod.POST)
    @ResponseBody
    public ResultData<Order> createOrder(String uid, String bankName, String name, String mobile, String address, String lon, String lat, String visitTime) {
        return orderService.createOrder(uid, bankName, name, mobile, address, lon, lat, visitTime);
    }

    @ApiOperation(value = "用户订单列表", notes = "用户订单列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "uid", value = "用户id", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "status", value = "订单状态", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "pageIndex", value = "第几页", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "一页几行", required = false, dataType = "int", paramType = "query"),
    })
    @RequestMapping(value = "/userOrderList", method = RequestMethod.POST)
    @ResponseBody
    public ResultData<Order> userOrderList(String uid, Integer status,
                                           @RequestParam(name = "pageIndex", defaultValue = "1") Integer pageIndex,
                                           @RequestParam(name = "pageSize", defaultValue = "5") Integer pageSize) {
        return orderService.userOrderList(uid, status, pageIndex, pageSize);
    }

    @ApiOperation(value = "业务人员订单列表", notes = "业务人员订单列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "uid", value = "业务人员id", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "status", value = "订单状态", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "pageIndex", value = "第几页", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "一页几行", required = false, dataType = "int", paramType = "query"),
    })
    @RequestMapping(value = "/bankPersonOrderList", method = RequestMethod.POST)
    @ResponseBody
    public ResultData<Order> bankPersonOrderList(String uid, Integer status,
                                                 @RequestParam(name = "pageIndex", defaultValue = "1") Integer pageIndex,
                                                 @RequestParam(name = "pageSize", defaultValue = "5") Integer pageSize) {
        return orderService.bankPersonOrderList(uid, status, pageIndex, pageSize);
    }

    @ApiOperation(value = "订单详情", notes = "订单详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "订单id", required = true, dataType = "String", paramType = "query"),
    })
    @RequestMapping(value = "/orderDetail", method = RequestMethod.POST)
    @ResponseBody
    public ResultData<Order> orderDetail(Integer id) {
        return orderService.orderDetail(id);
    }

    @ApiOperation(value = "取消订单", notes = "取消订单")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "订单id", required = true, dataType = "String", paramType = "query"),
    })
    @RequestMapping(value = "/cancelOrder", method = RequestMethod.POST)
    @ResponseBody
    public ResultData<Order> cancelOrder(Integer id) {
        return orderService.updOrderStatus(id,2);
    }

    @ApiOperation(value = "完成订单", notes = "完成订单")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "订单id", required = true, dataType = "String", paramType = "query"),
    })
    @RequestMapping(value = "/overOrder", method = RequestMethod.POST)
    @ResponseBody
    public ResultData<Order> overOrder(Integer id) {
        return orderService.updOrderStatus(id,1);
    }
}
